class FirstPage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [],
            thumburl: '',
            name: '',
            showchose: !1,
            id: '0',
            partcount: 1,
            parts: [{ src: '' }, { src: '' }, { src: '' }],
            categorylist: [],
            select_swiperlink: { name: '请选择' },
            swiperimglist: [],
            keyword: '',
            showdesc: !1,
            category_select_list: [],
            recommendtablehtml: [],
            recommendlist: [],
            goods_select_html: [],
            currentswipertype: 0,
            swiperlinkhtml: [],
            swipertablehtml: [],
            swiperimghtml: [],
            subtitle: '',
            totalamount: 0,
            roomlist: [],
            roomdlist: [],
            exportlist: [],
            choselist: [],
            showjf: !1,
            swiper: {
                imgs: [],
                links: []
            },
            fileimgshow: !0,
            imgstate: '',
            imgsrc: '',
            to: '',
            showpage: !1,
        };
    }


    ccheck() {
        this.freshlist()
        // let pwd = prompt('请输入密码')
        // dz_category_checkpwd(md5(pwd + Constant.SALT),res=>{
        //     if(res.data==true){

        //     }else{
        //         this.ccheck()
        //     }
        // })
    }


    componentDidMount() {
        $('.modal1').hide()

        let permission = $.cookie('permission'), shopname = $.cookie('shopname'), deadline = $.cookie('deadline'),that = this
        laydate.render({
            elem: '#test1', //指定元素
            type: 'datetime',
            done: function (value, date, endDate) {
                that.setState({ startdate: value })
            }
        });
        laydate.render({
            elem: '#test2', //指定元素
            type: 'datetime',
            done: function (value, date, endDate) {
                that.setState({ enddate: value })
            }
        });
        // console.log( ,'deadlinedeadline');

        this.setState({ permission, shopname, deadline: formatDate1(new Date(deadline)) })
        this.ccheck()
        // console.log());
        // if()

        //   this.freshlist()




        $("#input").keydown(function (e) {
            // 当 keyCode 是13时,是回车操作
            if (e.keyCode == 13) {
                // 编写业务代码...
                if (this.state.showpage) {
                    that.freshlist()
                }

                // 取消之前的keydown事件
                e.preventDefault();
            }
        })



        // dzroom_getlist(res => {
        //     if (res.issuccess == 1) {
        //         this.setState({roomlist:res.list})
        //     }
        // })

    }
    freshlist() {
        this.setState({roomdlist:[]})
        let{keyword,startdate,enddate} = this.state,that=this,err=''
        console.log(startdate,'startdatestartdate');
        if (startdate) {
            if (!enddate) {
                err = '结束时间不能为空'
            } else {
                if (new Date(startdate).getTime() > new Date(enddate).getTime()) {
                    err = '开始时间必须小于结束时间'
                } else {
                    startdate = new Date(startdate).getTime() / 1000;
                    enddate = new Date(enddate).getTime() / 1000;
                }
            }
        }
        if (err != "") {
            alert(err)
            return;
        }
        this.setState({ showpage: !0 }, () => {
            dz_getprojectdlist({ keyword, startdate,enddate}, res => {
                if (res.issuccess == 1) {
                    this.setState({ roomdlist: res.list },()=>{
                        res.list.forEach(x=>{
                            laydate.render({
                                elem: '#test'+x.id, //指定元素
                                done: function (value, date, endDate) {
                                // 
console.log(value,'valuevalue');

                                dz_changepoolroom({ id: x.id, pool: 'QD',date:new Date(value).getTime()/1000 }, res => {
                                    if (res.issuccess == 1) {
                                        //alert('转入成功')
                                        that.freshlist()
                                    }
                                    //this.freshlist()
                                })

                                   dz_updatetime({id:x.id,date:new Date(value).getTime()/1000 },res=>{

                                   })
                                }
                            });
                        })
                       
                    })
                }
            })
        })



    }

    quit() {
        $.cookie('token', '');
        // $.cookie('token', 'kJjOJgi0w7Nt8ozNOVbecvEPB1Wp4hLV');
        $.cookie('id', '');
        $.cookie('permission', '');
        // setalllist(res => {
        // })
        window.location.href = 'shopunknwo.html';
    }





    /**新建 */
    add() {
        // $('.modal1').show()
        // var name = prompt('请输入房间名称')
        // if (name != '') {
        //     aoedzroom({ name }, res => {
        //         if (res.issuccess == 1) {
        //             this.freshlist()
        //         } else {
        //             alert(res.msg)
        //         }
        //     })
        // }

        // this.setState({showchose:!0})
    }


    // 编辑
    edit(x) {
        var name = prompt('请编辑房间名称', x.name)
        if (name != '' && name != null && name != x.name) {
            //  console.log(name,'name');

            dz_projectdetail_add({ selectid: x.id, name }, res => {
                if (res.issuccess == 1) {
                    //   alert('修改成功')
                    this.freshlist()
                } else {
                    alert(res.msg)
                }
            })
        }

        // 
    }
    tosub(x) {
        window.location.href = "./dz_subcate.html?id=" + x.id + "&name=" + x.name;
    }
    // 排序




    // 删除
    del(e, cid) {
        this.setState({ delid: e, newcid: cid }, () => {
            $('#myModal').modal('toggle');
        })
    }

    confirmdel() {
        let { delid, start } = this.state
        dz_projectdetail_del(delid, res => {
            if (res.issuccess == 1) {
                //  alert('删除成功')
                $('#myModal').modal('toggle');
                this.freshlist(start)
            } else {
                $('#myModal').modal('toggle');
                alert(res.msg);
            }
        })
    }

    closemodal() {
        $('.modal1').hide()
    }

    inputchange(prop, e) {
        this.setState({ [prop]: e.target.value })
    }
    confirm() {
        let { _desc, selectid } = this.state;
        if (_desc != '') {
            // alert('请输入')
            // return;
            dz_projectdetail_setdesc({ desc: _desc, id: selectid }, res => {
                this.setState({ showdesc: !1 })
                if (res.issuccess == 1) {
                    this.freshlist()
                } else {
                    alert(res.msg)
                }
            })

        }
        // choselist.forEach(x=>{
        //     idarr.push(x.id)
        // })
        //  console.log({selectid,ids:idarr.toString(),name:fanghao});


    }

    toitem(id) {
        window.location.href = './dz_newroom.html?id=' + id


        //   let {roomdlist,roomlist} = this.state,item=roomdlist[i],choselist=[];
        //   let idarr = item.roomids.split(',')
        //   idarr.forEach(x=>{
        //     roomlist.forEach(y=>{
        //         if(x==y.id)choselist.push(y)
        //     })
        //   })
        //   console.log(choselist,'choselistchoselist');
        //   this.setState({showchose:!0,selectid:item.id,fanghao:item.name,choselist})
    }
    copy(id) {
        dz_projectd_copy(id, res => {
            if (res.issuccess == 1) {
                this.freshlist()
            }
        })
        //  let 
        // dz_projectdetail_editdata(data, res => {
        //     if (res.issuccess == 1) {
        //         if (Number(id) > 0) {
        //         } else {
        //             this.setState({ id: res.id })
        //         }
        //         this.setState({ exportlist })

        //         //alert('保存成功')
        //         // if(ismoban){
        //         //     window.location.href='./dz_newroom.html?id='+res.id
        //         // }
        //     }
        // })
    }

    selectchange(e) {
        this.setState({ selectroomid: e.target.value })

    }


    addroom() {
        let { selectroomid, exportlist, totalamount } = this.state;
        if (Number(selectroomid) > 0) {
            dz_getprojectitemlist(selectroomid, res => {
                if (res.issuccess == 1) {
                    let { room, wj, cp } = res;
                    let wjtotal = 0, cptotal = 0, cptotalcount = 0, wjtotalcount = 0, amount = 0
                    wj.forEach(x => {
                        wjtotal = (Number(wjtotal) + (Number(x.singleprice) * Number(x.count))).toFixed(2)
                        wjtotalcount = (Number(wjtotalcount) + Number(x.count)).toFixed(2)
                    })
                    cp.forEach(x => {
                        cptotalcount = (Number(cptotalcount) + Number(x.count)).toFixed(2)
                        cptotal = (Number(cptotal) + (Number(x.singleprice) * Number(x.count))).toFixed(2)
                    })
                    amount = (Number(wjtotal) + (Number(cptotal))).toFixed(2)
                    totalamount = (Number(totalamount) + (Number(amount))).toFixed(2)
                    let item = { room, wjtotal, cptotal, cptotalcount, wjtotalcount, amount, wj, cp }
                    console.log(item, 'item');
                    exportlist.push(item)
                    console.log(exportlist, 'exportlist');
                    this.setState({ exportlist, totalamount })
                }
            })
        }
    }

    clickitem(i) {
        let { roomlist, choselist } = this.state;
        choselist.push(roomlist[i])
        console.log(choselist, 'choselist');
        this.setState({ choselist })

    }
    choseitem(i) {
        let { choselist } = this.state;
        choselist.splice(i, 1)
        this.setState({ choselist })
    }
    input(e) {
        this.setState({ fanghao: e.target.value })
    }

    tochi(e, e1) {
        console.log({ e, e1 });
        // var b = 
        if (confirm(`确定要转入${e1 == 0 ? '签单' : '下单'}池吗？`)) {
            dz_changepoolroom({ id: e, pool: e1 == 0 ? 'QD' : 'XD' }, res => {
                if (res.issuccess == 1) {
                    alert('转入成功')
                }
                //this.freshlist()
            })
        }

        // zroom_getlist(e,res => {
        //     if (res.issuccess == 1) {
        //         this.setState({roomlist:res.list})
        //     }
        // })
    }

    setoorder(id) {
        var val = prompt('请输入排序')
        if (val != null) {
            dz_projectdetail_setorder({ id, orderid: val }, res => {
                if (res.issuccess == 1) {
                    this.freshlist()
                }
            })
        }

    }


    render() {
        var { permission, showpage, startdate, enddate, showjf, shopname, fanghao, roomdlist, name, showchose, showdesc, choselist, _desc, subtitle, roomlist, keyword } = this.state;

        return (


            <div className="breadLinebox">
                {
                    showjf ?
                        <div className="modal_jf">
                            <div onClick={() => { this.setState({ showjf: !1 }) }} className="mask"></div>
                            <div className="wrap">
                                <img src="./src/jiaofei.jpg" alt="" srcset="" />
                            </div>

                        </div>
                        : null
                }

                {showchose ? <div className="modal_chose">

                    <div onClick={() => { this.setState({ showchose: !1 }) }} className="mask"></div>
                    <div className="wrap">
                        <div className="name">
                            <p>地址</p>
                            <input type="text" placeholder="请输入业主地址" value={fanghao} onChange={this.input.bind(this)} />
                        </div>
                        <div className="title">选择房间</div>
                        <div className="w">
                            <div className="left">
                                {
                                    roomlist.map((x, i) => {
                                        return (
                                            <div onClick={this.clickitem.bind(this, i)} className={`item ${x.c ? 'c' : ''}`}>
                                                {x.name}
                                            </div>
                                        )
                                    })
                                }
                            </div>
                            <div className="left r">
                                {
                                    choselist.map((x, i) => {
                                         return (
                                            <div onClick={this.choseitem.bind(this, i)} className='item'>
                                                {x.name}
                                            </div>
                                        )
                                    })
                                }

                            </div>
                        </div>
                        <div className="btns">
                            <div onClick={this.confirm.bind(this)} className="confirm">确定</div>
                            <div onClick={() => { this.setState({ showchose: !1 }) }} className="cancel">取消</div>
                        </div>
                    </div>
                </div>

                    : null

                }

                {showdesc ?
                    <div className="modal1" >
                        <div onClick={this.closemodal.bind(this)} className="mask"></div>
                        <div className="wrap">
                            <div className="content">

                                <textarea placeholder="请输入跟踪信息" value={_desc} onChange={this.inputchange.bind(this, '_desc')}></textarea>
                                {/* <input  allowClear  className="input" /> */}
                                {/* <p className="p2">{zje}</p> */}
                            </div>

                            <div className="btns">
                                <p className="add" onClick={this.confirm.bind(this)}>确定</p>
                                <p className="add" onClick={this.closemodal.bind(this)}>取消</p>
                            </div>
                        </div>
                    </div>
                    :
                    null
                }


                <Modal content='确定要删除吗？' click={this.confirmdel.bind(this)} />


                <div style={{ display: showpage ? '' : 'none' }} className='content_wrap panel-default content_wrap'>
                    {/* <div onClick={()=>{window.location.href='./dz_cate.html'}} className='breadLine '>
                        前往分类管理
                    </div> */}
                    {/* <div className='inputs panel-body'>
                        <h3>首页管理</h3>
                    </div> */}
                    <div className="content form">
                        {/* <div style={{display:clicknew?"":"none"}} id="div"> */}

                        <div className="tabletit" >

                            <div className="shopname">{shopname}</div>

                           

                            <antd.Select showSearch  style={{ width: "100px" }}  >
                                                                                <option value={-1}>请选择 </option>
                                                                                <option value={1}>1 </option>
                                                                                <option value={2}>2 </option>
                                                                                <option value={3}>3 </option>
                                                                                <option value={34}>34 </option>
                                                                                <option value={35}>35 </option>
                                                                                </antd.Select>
                            {/* <p className="delall"><img src="./src/delall.png"/>批量删除</p> */}
                            {/* <p className="add" onClick={()=>{this.setState({showchose:!0})}}>新建报价</p> */}
                            {/* <p className="add" onClick={()=>{this.setState({showchose:!0})}}>新建报价</p> */}
                            <p className="add" onClick={() => { window.location.href = './dz_newroom.html' }}>新建报价</p>
                            <p className="add" style={{ display: permission > 49 ? '' : 'none', 'cursor': 'pointer' }} onClick={() => { window.location.href = './dz_cate.html' }}>设置</p>
                            {/* {
                                permission > 49 ?
                                    <p className="add" style={{ 'cursor': 'pointer' }} onClick={() => { window.location.href = './dz_account.html' }}>账号管理</p>
                                    : null
                            } */}

                            <p className="add" style={{ 'cursor': 'pointer' }} onClick={() => { window.location.href = './dz_qdc.html' }}>签单池</p>
                            <p className="add" style={{ 'cursor': 'pointer' }} onClick={() => { window.location.href = './dz_qdc.html?t=1' }}>下单池</p>
                            {/* <p style={{ display: permission > 49 ? '' : 'none', 'cursor': 'pointer' }} className="add" onClick={() => { window.location.href = './dz_room.html' }}>模板设置</p> */}
                            <p className="add" onClick={() => { window.location.href = './dz_xdbj.html' }}>下单报价池</p>
                            <p className="add" onClick={() => { window.location.href = './dz_rubbish.html' }}>回收站</p>
                          
                            <p className="add" onClick={() => { this.quit() }}>退出</p>
                            <p onClick={() => { this.setState({ showjf: !0 }) }} className="add">缴费</p>
                            {/* <p className="add" style={{'cursor':'pointer'}} onClick={()=>{window.location.href='./dz_cate.html'}}>前往分类管理</p>
                            <p className="add" style={{'cursor':'pointer'}} onClick={()=>{window.location.href='./dz_main.html'}}>客户报价</p> */}
                            {/* <p className="add" style={{'cursor':'pointer'}} onClick={()=>{window.location.href='./export.html'}}>前往导出页</p> */}


                            <div className="searchbox">
                        <div className="inputbox">
                                <input type="text" id="test1" placeholder='请选择开始日期' value={startdate} className="input" />
                                <span>-</span>
                                <input type="text" id="test2" placeholder='请选择结束日期' value={enddate} className="input" />
                            </div>
                            <div className="content1">
                                <input id='input' placeholder="请输入业主地址或业务姓名" allowClear value={keyword} onChange={this.inputchange.bind(this, 'keyword')} className="input" />
                                <p className="add" onClick={() => { this.freshlist() }}>搜索</p>


                                {/* <p className="p2">{zje}</p> */}
                            </div>


                        </div>
                        <div className="shopnamer">
                                <span>有效期：{this.state.deadline}</span>
                                <span>
                                    服务电话:13559580055
                                </span>
                            </div>
                           

                        </div>
                    


                        <table className="tab">
                            <thead>
                                <tr>
                                    {/* <th className="minwidth tconter"><img src="./src/notselection.png"/></th> */}
                                    <th className="tconter">序号</th>
                                    <th className="tconter">排序</th>
                                    <th className="tconter">报价时间</th>
                                    <th className="tconter">修改时间</th>
                                    <th className="tconter">归属</th>
                                    <th className="tconter">业主地址</th>
                                    {/* <th className="tconter">跟踪信息</th> */}
                                    <th className="cz tconter">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {
                                    roomdlist.map((x, i) => {
                                        return (
                                            <tr key={i}>
                                                {/* <td className="minwidth tconter"><img src="./src/notselection.png"/></td>  */}
                                                {/* <td className="tconter">{x.state=="0"?"显示":"隐藏"}</td>  */}
                                                <td className="tconter">{i + 1}</td>
                                                <td onClick={this.setoorder.bind(this, x.id)} style={{ 'width': '40px' }} className="tconter">{x.orderid}</td>
                                                <td className="tconter">{x.createDate == "0001-01-01T00:00:00" ? '-' : formatDatenotime(new Date(x.createDate))}</td>
                                                <td className="tconter">{formatDate(new Date(x.updateDate))}</td>
                                                <td className="tconter">{x.nickname || '-'}</td>

                                                <td onClick={this.edit.bind(this, x)} className="tconter">{x.name}</td>
                                                {/* <td onClick={() => {
                                                    $('.modal1').show()
                                                    this.setState({ showdesc: !0, _desc: x._desc, selectid: x.id })
  

                                                }} className="tconter lines">{x._desc}</td> */}

                                                <td className="operatebox">
                                                    <div className='operate' id={"ope" + x.id}>
                                                        <p className='edit' onClick={this.toitem.bind(this, x.id)}>详情</p>
                                                        <p className='edit' onClick={this.copy.bind(this, x.id)}>复制</p>
                                                        {/* <p className='edit' id={'test'+x.id}>转入签单池</p> */}
                                                        <div  className="inputbox">
                                                        <input type="text" id={'test'+x.id} value={'转入签单池'}  className="input qdc" />
                                                        </div>
                                                        {/* <p className='edit' onClick={this.tochi.bind(this, x.id, 0)}>转入签单池</p> */}
                                                        
                                                        {/* <p className='edit' onClick={this.tochi.bind(this, x.id, 1)}>转入下单池</p> */}

                                                        {/* <div>
                                                       <img src={`./src/${x.state=="1"?"hide":"show"}.png`}/>
                                                       <p className='edit' onClick={this.setshow.bind(this,x.id,x.state)}>{x.state=="0"?"隐藏":"显示"}</p>
                                                   </div> */}
                                                        <div style={{  'cursor': 'pointer' }}>
                                                            <img src="./src/del.png" />
                                                            <p className='edit colred' onClick={this.del.bind(this, x.id)}>删除</p>
                                                        </div>
                                                    </div>
                                                </td>
                                            </tr>
                                        )
                                    })
                                }

                            </tbody>
                        </table>
                    </div>

                </div >


            </div >


        )
    }
}





ReactDOM.render(
    <div>
        {/* <LeftMenu code='0' /> */}
        <FirstPage />
    </div>
    //<Barrage/>
    , $('.container')[0]
)